package com.mooco.dongba.sys.controller;

import com.mooco.dongba.common.pojo.JsonResult;
import com.mooco.dongba.sys.pojo.SysMenu;
import com.mooco.dongba.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 加载菜单页面数据
     *
     * http://localhost/menu/doFindObjects
     *
     * @return
     */
    @RequestMapping("/doFindObjects")
    public JsonResult doFindObjects() {
        return new JsonResult(sysMenuService.findObjects());
    }

    @RequestMapping("/doDeleteObject")
    public JsonResult doDeleteObject(Integer id) {
        sysMenuService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    @GetMapping("/doFindZtreeMenuNodes")
    public JsonResult doFindZTreeMenuNodes() {
        return new JsonResult(sysMenuService.findZTreeMenuNodes());
    }

    @PostMapping("/doSaveObject")
    public JsonResult doSaveObject(SysMenu entity) {
        sysMenuService.insertObject(entity);
        return new JsonResult("save ok");
    }

    @PostMapping("/doUpdateObject")
    public JsonResult doUpdateObject(SysMenu entity) {
        sysMenuService.updateObject(entity);
        return new JsonResult("update ok");
    }
}
